package com.goertek.easyface.device;

import com.goertek.easyface.entity.AAcsFaceDeviceConfig;
import com.netsdk.lib.NetSDKLib;
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: easy-face
 * @description:
 * @author: devin.duj
 * @create: 2024-03-28 13:28
 */
@Slf4j
// 设备断线回调: 通过 CLIENT_Init 设置该回调函数，当设备出现断线时，SDK会调用该函数
@Component
public class DisConnectListener implements NetSDKLib.fDisConnect {
    @Autowired
    private DeviceStore deviceStore;

    public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
        // 断线提示
        log.info("Device {} Port {} DisConnect!", pchDVRIP, nDVRPort);
        AAcsFaceDeviceConfig deviceConfig = deviceStore.getDeviceConfigByIp(pchDVRIP);
        if(deviceConfig != null){
            log.info("DisConnect Device {} ", deviceConfig.getDeviceName());
            //TODO 根据断开时长，推送到责任人处理
        }
    }
}